package com.service.firstapp.controller;

import com.huawei.paas.cse.tcc.annotation.TccTransaction;
import com.service.firstapp.bean.People;
import com.service.firstapp.bean.PeopleInfo;
import com.service.firstapp.service.PeopleInfoService;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.ws.rs.core.MediaType;

/**
 * Created by wjh on 2018/3/27.
 */
@RestSchema(schemaId = "people")
@RequestMapping(path = "/thirdapp/people_info", produces = MediaType.APPLICATION_JSON)
public class PeopleInfoController {

    private static final Logger logger = LoggerFactory.getLogger(PeopleInfoController.class);

    @Autowired
    private PeopleInfoService peopleService;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public Object hellotest(@RequestParam(value = "name") String name) {
        return "hello " + name;
    }

    @RequestMapping(method = RequestMethod.POST)
    public Object addPeople(@RequestBody People people){
        long currentTime = System.currentTimeMillis();
        people.setStatus(0);
        PeopleInfo peopleInfo = new PeopleInfo();
        peopleInfo.setPeopleId(people.getPeopleId());
        peopleInfo.setSex(0);
        peopleInfo.setHeight(177);
        peopleInfo.setStatus(0);
        peopleService.addPeopleInfo(peopleInfo);
        logger.info("耗时：" + (System.currentTimeMillis() - currentTime));
        return people;
    }

    @RequestMapping(value = "/people_id",method = RequestMethod.PUT)
    public Object updatePeopleInfo(@RequestBody People people){
        PeopleInfo peopleInfo = new PeopleInfo();
        peopleInfo.setPeopleId(people.getPeopleId());
        peopleInfo.setSex(0);
        peopleInfo.setHeight(177);
        peopleInfo.setStatus(people.getStatus());
        peopleService.updatePeopleInfo(peopleInfo);
        return peopleInfo;
    }

}
